﻿using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Traceability.API.Applications.Command.TracebackCommand;
using Traceability.Domain.DTO.Output;
using Traceability.ErrorCode;

namespace Traceability.API.Controllers
{
    /// <summary>
    /// 溯源控制器——API
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class ManagementController : ControllerBase
    {
        private readonly IMediator mediator;

        public ManagementController(IMediator mediator)
        {
            this.mediator = mediator;
        }


        /// <summary>
        /// 商品溯源基础信息添加
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<APIResult<int>> TracebackAdd(TracebackAddCommand command)
        {
            return await mediator.Send(command);
        }


        /// <summary>
        /// 商品溯源基础信息查询
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<APIPaging<TracebackQueryDTO>> TracebackQuery([FromQuery]TracebackQueryCommand command)
        {
            return  mediator.Send(command);
        }


        /// <summary>
        /// 商品溯源基础信息删除
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<APIResult<int>> TracebackDelete([FromQuery]TracebackDelCommand command)
        {
            return await mediator.Send(command);
        }

        /// <summary>
        /// 商品溯源基础信息修改
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<APIResult<int>> TracebackUpDate(TracebackUpdateCommand command)
        {
            return await mediator.Send(command);
        }


        /// <summary>
        /// 商品溯源基础信息批量删除
        /// </summary>
        /// <param name=""></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<APIResult<int>> TracebackListDelete(List<int> Id)
        {
          TracebackListDelCommand command=new TracebackListDelCommand();
            command.Id = Id;
            return await mediator.Send(command);

        }


        /// <summary>
        /// 反填商品溯源基础信息
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<APIResult<TracebackFirstDTO>> TracebackListDelete([FromQuery]TracebackFirstCommand command)
        {
            return mediator.Send(command);
        }
    }
}
